package com.example.permission.service.impl;

import com.example.permission.common.page.Page;
import com.example.permission.entity.dto.page.SysLoginLogPageDTO;
import com.example.permission.entity.po.SysLoginLog;
import com.example.permission.mapper.SysLoginLogMapper;
import com.example.permission.service.SysLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 登录日志(SysLoginLog)表服务实现类
 *
 * @author xuwq
 * @date 2020-05-09 15:56:07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysLoginLogServiceImpl implements SysLoginLogService {

    @Autowired
    private SysLoginLogMapper sysLoginLogMapper;

    @Override
    public SysLoginLog queryById(Integer logId) {
        return this.sysLoginLogMapper.queryById(logId);
    }

    @Override
    public void updateLogoutTime(String userNo) {
        SysLoginLog sysLoginLogOld = sysLoginLogMapper.queryByUserNo(userNo);
        if (sysLoginLogOld == null) {
            return;
        }
        SysLoginLog sysLoginLog = new SysLoginLog();
        sysLoginLog.setLogId(sysLoginLogOld.getLogId());
        sysLoginLog.setLogoutTime(new Date());
        sysLoginLogMapper.update(sysLoginLog);
    }

    @Override
    public Page<SysLoginLog> queryListByPage(SysLoginLogPageDTO sysLoginLogPageDTO) {
        int count = sysLoginLogMapper.queryCountByPage(sysLoginLogPageDTO);
        List<SysLoginLog> sysLoginLogList = sysLoginLogMapper.queryListByPage(sysLoginLogPageDTO);
        return new Page<>(count, sysLoginLogList);
    }

}